package com.itheima.controller;


import com.itheima.common.PGResult;
import com.itheima.common.PermissionResult;
import com.itheima.common.UserPage;
import com.itheima.pojo.pe.PeDto;
import com.itheima.pojo.pe.pe_permission_group;
import com.itheima.service.PGService;
import com.itheima.service.PPGService;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permissions")
public class PermissionController {
    @Autowired
    private PGService pgService;
    @Autowired
    private PPGService ppgService;
    @Autowired
    private PermissionService permissionService;

    //权限组添加
    @PostMapping
    public void addGroup(@RequestBody PeDto peDto){
        ppgService.addGroup(peDto);
    }

    //权限组列表
    @GetMapping
    public UserPage list(Long page, Long pagesize, String title){
        UserPage list = pgService.list(page,pagesize,title);
        return list;
    }

    //权限组详情
    @GetMapping("/{id}")
    public PermissionResult modify(Integer id){
        PermissionResult result  = pgService.modify(id);
        return result;
    }

    //权限组修改
    @PutMapping("/{id}")
    public void modifyPermission(@PathVariable Long id,@RequestBody PeDto peDto){
        pgService.modifyPermission(id,peDto);
    }

    //权限删除
    @DeleteMapping("/{id}")
    public void removeById(@PathVariable Long id){
        pgService.removeById(id);
    }

    //权限组简单列表
    @GetMapping("/simple")
    public List<PGResult> permissionSimple(){
        return pgService.permissionSimple();
    }
}
